﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Web.UI;

using Developmentalmadness.Web.UI.AjaxAbstractions;

[assembly: WebResource("Developmentalmadness.Web.UI.ExtJsControlLibrary.Scripts.resources.css.panel.css", "text/css", PerformSubstitution=true)]
namespace Developmentalmadness.Web.UI.ExtJsControlLibrary
{
    public class ExtJsPanel : ExtJsContainer
    {
        private String _shadow = null;

        public override List<ScriptReference> GetScriptReferences()
        {
            return base.GetScriptReferences();
        }

        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.Panel";

            String[] properties = new String[]{
                "animCollapse", "autoLoad", "autoScroll", "baseCls", "bbar", "bodyBorder",
                "border", "bufferResizeMilliseconds", "buttonAlign", "buttons", "collapseFirst", 
                "collapsed", "collapsedCls", "collapsible", "draggable", "elements",
                "floating", "footer", "frame", "header", "headerAsText", "hideCollapseTool", "html",
                "iconCls", "keys", "maskDisabled", "minButtonWidth", "shadow", "shadowOffset",
                "shim", "tabTip", "tbar", "title", "titleCollapse", "tools"
            };

            Type component = typeof(ExtJsPanel);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'ExtJsPanel.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                {
                    continue;
                }

                if (!(value is String))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }

            // applyTo
            if (!String.IsNullOrEmpty(applyTo))
            {
                if (String.Compare(applyTo, ID, true) == 0)
                    desc.AddPropertyBase("applyTo", String.Format("'{0}'", ClientID));
                else
                    desc.AddPropertyBase("applyTo", String.Format("'{0}'", GetControlID(applyTo)));
            }
            // contentEl
            if (!String.IsNullOrEmpty(contentEl))
            {
                if (String.Compare(contentEl, ID, true) == 0)
                    desc.AddPropertyBase("contentEl", String.Format("'{0}'", ClientID));
                else
                    desc.AddPropertyBase("contentEl", String.Format("'{0}'", GetControlID(contentEl)));
            }
            else if (Body != null)
                desc.AddPropertyBase("contentEl", String.Format("'{0}'", GetControlID("Body")));

            //RegisterClientEvents(desc);

            return list;
        }

        #region Public Properties

        public Boolean? animCollapse { get; set; }

        /// <summary>
        /// The id (ClientId) of the node, a DOM node or an existing Element corresponding to a DIV
        /// </summary>
        public String applyTo { get; set; }

        public String autoLoad { get; set; }

        public Boolean? autoScroll { get; set; }

        public String baseCls { get; set; }

        public String bbar { get; set; }

        public Boolean? bodyBorder { get; set; }

        public Style bodyStyle { get; set; }

        public Boolean? border { get; set; }

        public Int32? bufferResizeMilliseconds { get; set; }

        public align? buttonAlign { get; set; }

        public String buttons { get; set; }

        public Boolean? collapseFirst { get; set; }

        public Boolean? collapsed { get; set; }

        public String collapsedCls { get; set; }

        public Boolean? collapsible { get; set; }

        public String contentEl { get; set; }

        public Boolean? draggable { get; set; }

        public String elements { get; set; }

        public Boolean? floating { get; set; }

        public Boolean? footer { get; set; }

        public Boolean? frame { get; set; }

        public Boolean? header { get; set; }

        public Boolean? headerAsText { get; set; }

        public Boolean? hideCollapseTool { get; set; }

        public String html { get; set; }

        public String iconCls { get; set; }

        public String keys { get; set; }

        public Boolean? maskDisabled { get; set; }

        public Int32? minButtonWidth { get; set; }

        public String shadow
        {
            get
            {
                return _shadow;
            }
            set
            {
                Boolean boolValue;
                if (!String.IsNullOrEmpty(value) && !Boolean.TryParse(value, out boolValue))
                {
                    try
                    {
                        Enum.Parse(typeof(shadowMode), value, true);
                    }
                    catch (ArgumentException)
                    {
                        throw;
                    }
                }
            }
        }

        public Int32? shadowOffset { get; set; }

        public Boolean? shim { get; set; }

        public String tabTip { get; set; }

        public String tbar { get; set; }

        public String title { get; set; }

        public Boolean? titleCollapse { get; set; }

        public String tools { get; set; }

        #endregion

    }
}
